package info.nene_loveplus.controller.pub.comment;

import info.nene_loveplus.service.BlogService;

import java.util.logging.Logger;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;
import org.slim3.controller.validator.RequiredValidator;
import org.slim3.controller.validator.Validators;

public class EntryController extends Controller {

	private BlogService blogService = new BlogService();

	private Logger logger = Logger.getLogger(EntryController.class.getName());

	@Override
	public Navigation run() throws Exception {
		logger.fine("comment entry");

		Validators v = new Validators(request);
		v.add("entryKey", RequiredValidator.INSTANCE);
		v.add("comment", RequiredValidator.INSTANCE);
		if (!v.validate()) {
			return forward("/pub/single?key=" + asString("entryKey"));
		}

		blogService.postComment(asKey("entryKey"), asString("name"),
				asString("comment"));

		return redirect("/pub/single?key=" + asString("entryKey"));
	}
}
